package net.shopxx.action.admin;

import javax.annotation.Resource;

import net.shopxx.entity.Indexfloor;
import net.shopxx.service.IndexfloorService;

import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.BeanUtils;

import com.opensymphony.xwork2.interceptor.annotations.InputConfig;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.Validations;

/**
 * 后台Action类 - 首页楼层
 */

@ParentPackage("admin")
public class IndexfloorAction extends BaseAdminAction {


	/**
     *
     */
    private static final long serialVersionUID = -4203398899472303153L;

    private Indexfloor indexfloor;

	@Resource
	private IndexfloorService indexfloorService;

	// 是否已存在 ajax验证
	public String checkName() {
		String oldValue = getParameter("oldValue");
		String newValue = indexfloor.getName();
		if (indexfloorService.isUnique("name", oldValue, newValue)) {
			return ajaxText("true");
		} else {
			return ajaxText("false");
		}
	}

	// 添加
	public String add() {
		return INPUT;
	}

	// 编辑
	public String edit() {
	    indexfloor = indexfloorService.load(id);
		return INPUT;
	}

	// 列表
	public String list() {
		pager = indexfloorService.findByPager(pager);
		return LIST;
	}

	// 删除
	public String delete() {
	    indexfloorService.delete(ids);
		return ajaxJsonSuccessMessage("删除成功！");
	}

	// 保存
	@Validations(
		requiredStrings = { 
			@RequiredStringValidator(fieldName = "indexfloor.name", message = "楼层不允许为空!") 
		}
	)
	@InputConfig(resultName = "error")
	public String save() {
	  //  indexfloor.setFloortabSet(null);
	    indexfloorService.save(indexfloor);
		redirectionUrl = "indexfloor!list.action";
		return SUCCESS;
	}

	// 更新
	// 保存
    @Validations(
        requiredStrings = { 
            @RequiredStringValidator(fieldName = "indexfloor.name", message = "楼层不允许为空!") 
        }
    )
	@InputConfig(resultName = "error")
	public String update() {
		Indexfloor persistent = indexfloorService.load(id);
		BeanUtils.copyProperties(indexfloor, persistent, new String[] {"id", "createDate", "modifyDate", "proCateSet", "floortabSet","productCategoryList"});
		indexfloorService.update(persistent);
		redirectionUrl = "indexfloor!list.action";
		return SUCCESS;
	}

    public Indexfloor getIndexfloor() {
        return indexfloor;
    }

    public void setIndexfloor(Indexfloor indexfloor) {
        this.indexfloor = indexfloor;
    }

    

	

}